package cn.tiancaifan.micro.controller.system.basic;


import cn.tiancaifan.micro.entity.Level;
import cn.tiancaifan.micro.entity.SystemResults;
import cn.tiancaifan.micro.service.LevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/basic/lev")
public class LevelController {

    @Autowired
    LevelService levelService;

    @GetMapping("/")
    public SystemResults getLevels(){
        SystemResults ok = SystemResults.ok(null, levelService.getLevels());
        return ok;
    }

    @PostMapping("/")
    public SystemResults addLevel(@RequestBody Level level){
        int i = levelService.addLevel(level);
        if(i == 1 ){
            return SystemResults.ok("添加成功");
        }else{
            return SystemResults.error("添加失败");
        }
    }


    @DeleteMapping("/{id}")
    public SystemResults deleteLevel(@PathVariable("id") Integer id){
        int i = levelService.deleteLevel(id);
        if(i == 1 ){
            return SystemResults.ok("删除成功");
        }else{
            return SystemResults.error("删除失败");
        }
    }
}
